<template>
  <!-- 维护作业-MI automapping页面 -->
  <div class="fillcontain">
    <el-form :model="searchParams" :rules="searchRules" ref="searchForm" label-width="140px" class="search_container">
      <el-row>
        <el-col :span="6">
          <el-form-item label="需求号码" prop="srpisno">
            <el-input clearable v-model="searchParams.srpisno" maxLength="10"
                      @blur="searchParams.srpisno = searchParams.srpisno.toUpperCase()" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="PRODUCT CODE" prop="crtable">
            <el-input clearable v-model="searchParams.crtable" maxLength="4"
                      @blur="searchParams.crtable = searchParams.crtable.toUpperCase()" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="险种类别" prop="planType">
            <el-select v-model="searchParams.planType" placeholder="">
              <el-option
                  v-for="item in planTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" class="text_center">
          <el-button type="primary" icon="el-icon-search" @click="subGetList"></el-button>
          <el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
        </el-col>
      </el-row>
    </el-form>
    <div class="contain">
      <el-row class="bgfff pb15">
        <el-col :span="24" class="pt5">
          <el-button type="danger" plain @click="addClick">新增</el-button>
        </el-col>
      </el-row>
      <!-- 查询结果 -->
      <div class="table_container">
        <el-table
            v-loading="loading"
            :data="tableData"
            highlight-current-row
            header-cell-class-name="table-header-class"
            style="width:100%">
          <el-table-column
              min-width="180"
              property="crtable"
              label="PRODUCT CODE"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="180"
              property="productNameSdesc"
              label="PRODUCTNAMESDESC"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="180"
              property="productNameMdesc"
              label="PRODUCTNAMEMDESC"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="180"
              property="productNameLdesc"
              label="PRODUCTNAMELDESC"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="180"
              property="productFundtype"
              label="PRODUCTFUNDTYPE"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="180"
              property="productType"
              label="PRODUCTTYPE"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="180"
              property="productFormat"
              label="PRODUCT FORMAT"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="220"
              property="customerName"
              label="PRODUCT BENEFITTRIGGER"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="180"
              property="productSection"
              label="PRODUCT SECTION"
              align='center'
              show-overflow-tooltip>
            <template slot-scope="scope">
              <el-select v-model="scope.row.productSection" :disabled="true" placeholder="">
                <el-option
                    v-for="item in productSections"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
              min-width="150"
              property="planType"
              label="险种类别"
              align='center'
              show-overflow-tooltip>
            <template slot-scope="scope">
              <el-select v-model="scope.row.planType" :disabled="true" placeholder="">
                <el-option
                    v-for="item in planTypes"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="fullName"
              label="全称"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="abbrName"
              label="简称"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="150"
              property="planPeriod"
              label="期限类别"
              align='center'
              show-overflow-tooltip>
            <template slot-scope="scope">
              <el-select v-model="scope.row.planPeriod" :disabled="true" placeholder="">
                <el-option
                    v-for="item in planPeriods"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="isDividend"
              label="是否分红保险"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="isDepo"
              label="是否储金险种"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="islegal"
              label="是否法定"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="isAnnu"
              label="是否年金型"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="isvalid"
              label="是否有效"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="productRemark"
              label="备注"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="srpisno"
              label="需求号码"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="updateInd"
              label="更新方式"
              align='center'
              show-overflow-tooltip>
            <template slot-scope="scope">
              <el-select v-model="scope.row.updateInd" :disabled="true" placeholder="">
                <el-option
                    v-for="item in updateInds"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <!-- <el-table-column
          min-width="120"
             property="jobName"
             label="Job Name"
             align='center'
             show-overflow-tooltip>
          </el-table-column>
          <el-table-column
          min-width="120"
             property="userProfile"
             label="User Profile"
             align='center'
             show-overflow-tooltip>
          </el-table-column>
          <el-table-column
          min-width="120"
             property="datime"
             label="Date Time"
             align='center'
             show-overflow-tooltip>
          </el-table-column> -->
          <el-table-column
              fixed="right"
              min-width="120"
              label="操作"
              align='center'>
            <template slot-scope="scope">
              <!-- <el-button type="text" size="small" @click="modifyClick(scope.row)">修改</el-button> -->
              <span class="operationIcon" @click="modifyClick(scope.row)">
                              <el-tooltip class="item" effect="light" content="修改" placement="top">
                                <i class="el-icon-edit"></i>
                              </el-tooltip>
                          </span>
              <!-- <el-button type="text" size="small" @click="deleteData(scope.row)">删除</el-button> -->
              <span class="operationIcon ml5" @click="deleteData(scope.row)">
                                <el-tooltip class="item" effect="light" content="删除" placement="top">
                                  <i class="el-icon-delete"></i>
                                </el-tooltip>
                            </span>
            </template>
          </el-table-column>
        </el-table>
        <el-row>
          <el-col :span="24">
            <div class="pagination">
              <el-pagination
                  background
                  v-if='paginations.total > 0'
                  :page-sizes="paginations.pageSizes"
                  :page-size="paginations.pageSize"
                  :layout="paginations.layout"
                  :total="paginations.total"
                  :current-page='paginations.pageIndex'
                  @current-change='handleCurrentChange'
                  @size-change='handleSizeChange'>
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <!-- 弹框 修改-->
    <el-dialog
        title="MI automapping"
        :visible.sync="showDialog"
        width="60%"
        center>
      <el-form ref="form" :rules="rules" :model="form">
        <el-row>
          <el-col :span="10" class="">
            <el-form-item label="PRODUCT CODE" prop="crtable">
              <el-input clearable v-model="form.crtable" @blur="form.crtable = toCDB(form.crtable)"
                        :disabled="form.method == 'modify' ? true : false" maxlength="4" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="2" class="">&nbsp;</el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="PRODUCT FUNDTYPE" prop="productFundtype">
              <el-select v-model="form.productFundtype" @change="changeProductTypes" placeholder="">
                <el-option
                    v-for="item in productFundtypes"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="PRODUCT TYPE" prop="productType">
              <el-select v-model="form.productType" placeholder="">
                <el-option
                    v-for="item in productTypes"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2" class="">&nbsp;</el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="PRODUCT FORMAT" prop="productFormat">
              <el-select v-model="form.productFormat" placeholder="">
                <el-option
                    v-for="item in productFormats"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="PRODUCT BENEFIT TRIGGER" prop="productBenefittrigger">
              <el-select v-model="form.productBenefittrigger" placeholder="">
                <el-option
                    v-for="item in productBenefittriggers"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2" class="">&nbsp;</el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="PRODUCT SECTION" prop="productSection">
              <el-select v-model="form.productSection" placeholder="">
                <el-option
                    v-for="item in productSections"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="险种类别" prop="planType">
              <el-select v-model="form.planType" placeholder="">
                <el-option
                    v-for="item in planTypes"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2" class="">&nbsp;</el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="期限类别" prop="planPeriod">
              <el-select v-model="form.planPeriod" placeholder="">
                <el-option
                    v-for="item in planPeriods"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="PRODUCT CODE" prop="isDividend">
              <el-select v-model="form.isDividend" placeholder="">
                <el-option
                    v-for="item in yesOrno"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2" class="">&nbsp;</el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="是否储金险种" prop="isDepo">
              <el-select v-model="form.isDepo" placeholder="">
                <el-option
                    v-for="item in yesOrno"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="是否法定" prop="islegal">
              <el-select v-model="form.islegal" placeholder="">
                <el-option
                    v-for="item in yesOrno"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2" class="">&nbsp;</el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="是否年金型" prop="isAnnu">
              <el-select v-model="form.isAnnu" placeholder="">
                <el-option
                    v-for="item in yesOrno"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="是否有效" prop="isvalid">
              <el-select v-model="form.isvalid" placeholder="">
                <el-option
                    v-for="item in yesOrno"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2" class="">&nbsp;</el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="需求号码" prop="srpisno">
              <el-input clearable v-model="form.srpisno" @blur="form.srpisno = form.srpisno.toUpperCase()"
                        maxLength="10" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="更新方式" prop="updateInd">
              <el-select v-model="form.updateInd" placeholder="">
                <el-option
                    v-for="item in updateInds"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2" class="">&nbsp;</el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="Job Name" prop="jobName">
              <el-input clearable v-model="form.jobName" maxlength="2" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="User Profile" prop="userProfile">
              <el-input clearable v-model="form.userProfile" maxlength="2" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="2" class="">&nbsp;</el-col>
          <el-col :span="10" class="common-box">
            <el-form-item label="Datetime" prop="datime">
              <el-input clearable v-model="form.datime" maxlength="2" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22" class="common-box">
            <el-form-item label="PRODUCT NAME SDESC" prop="productNameSdesc">
              <el-input clearable v-model="form.productNameSdesc" maxlength="20" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22" class="common-box">
            <el-form-item label="PRODUCT NAME MDESC" prop="productNameMdesc">
              <el-input clearable v-model="form.productNameMdesc" maxlength="40" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22" class="common-box">
            <el-form-item label="PRODUCT NAME LDESC" prop="productNameLdesc">
              <el-input clearable v-model="form.productNameLdesc" maxlength="60" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22" class="common-box">
            <el-form-item label="全称" prop="fullName">
              <el-input clearable v-model="form.fullName" maxlength="60" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22" class="common-box">
            <el-form-item label="简称" prop="abbrName">
              <el-input clearable v-model="form.abbrName" maxlength="20" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22" class="common-box">
            <el-form-item label="备注" prop="productRemark">
              <el-input clearable v-model="form.productRemark" maxLength="40" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
                <el-button @click="saveData" class="Defaultbutton">保 存</el-button>
                <el-button @click="showDialog = false">返 回</el-button>
            </span>
    </el-dialog>
  </div>
</template>

<script>
  import {mapState, mapGetters} from 'vuex'
  import constant from '@/utils/constant';
  import * as api from '@/api/setting/maintain/miAutomapping.js';
  import {checkSrpisno} from "@/api/setting/replyCodeMaintenance.js";
  import validRules from "@/utils/validRules";

  export default {
    data() {
      var validateSrpisno = (rule, value, callback) => {
        let para = {
          "srpisno": value
        }
        if (value) {
          checkSrpisno(para).then(res => {
            if (res.resultCode == constant.SUCCESS) {
              if (res.data == 0) {
                callback(new Error('需求号码必须存在且尚未结案'));
              } else {
                console.log(res)
                callback();
              }
            } else {
              callback(new Error('需求号码必须存在且尚未结案'));
            }
          }).catch(err => {
            callback(new Error('需求号码必须存在且尚未结案'));
          })
        } else {
          callback();
        }
      };
      var containChinese = (rule, value, callback) => {
        var that = this;
        let CHNReg = /[\u4e00-\u9fa5]/;//汉字的正则表达式
        if (CHNReg.test(value)) {
          callback(new Error('不能为中文!'));
        } else {
          callback();
        }
      };
      return {
        valueDate: '',
        showDialog: false,//默认隐藏 修改弹框
        // 查询条件
        rules: {
          crtable: [
            {required: true, message: '请输入PRODUCT CODE', trigger: 'blur'},
            {validator: containChinese, trigger: 'blur'}
          ],
          productNameSdesc: [
            {required: true, message: '请输入PRODUCT NAME SDESC', trigger: 'blur'},
            {validator: containChinese, message: 'PRODUCT NAME SDESC不能含有汉字', trigger: 'blur'}
          ],
          productNameMdesc: [
            {required: true, message: '请输入PRODUCT NAME MDESC', trigger: 'blur'},
            {validator: containChinese, message: 'PRODUCT NAME MDESC不能含有汉字', trigger: 'blur'}
          ],
          productNameLdesc: [
            {required: true, message: '请输入PRODUCT NAME LDESC', trigger: 'blur'},
            {validator: containChinese, message: 'PRODUCT NAME LDESC不能含有汉字', trigger: 'blur'}
          ],
          abbrName: [
            {required: true, message: '请输入简称', trigger: 'blur'},
          ],
          srpisno: [
            {required: true, message: '请输入需求号码', trigger: 'blur'},
            {validator: validateSrpisno, trigger: 'blur'},
            {validator: containChinese, trigger: 'blur'},
          ],
        },
        searchParams: {
          crtable: '',
          planType: '',
          srpisno: '',
        },
        searchRules: {
          crtable: [
            {validator: validRules.isEnglishOrNumber, message: '请正确输入PRODUCT CODE！', trigger: 'blur'}
          ],
          srpisno: [
            {validator: validRules.isEnglishOrNumber, message: '请正确输入需求号码！', trigger: 'blur'}
          ],
          planType: [],
        },
        tableData: [],
        srpisno_temp: '', // 修改时缓存需求号，保存时校验，如果没改变则无需校验
        loading: false,

        form: {
          crtable: '',
          productFundtype: '',
          productType: '',
          productFormat: '',
          planPeriod: '',
          isDepo: '',
          productBenefittrigger: '',
          planType: '',
          isDividend: '',
          productSection: '',
          islegal: '',
          isAnnu: '',
          isvalid: '',
          srpisno: '',
          updateInd: '',
          productNameSdesc: '',
          productNameMdesc: '',
          productNameLdesc: '',
          fullName: '',
          abbrName: '',
          productRemark: '',
          method: '',
        },
        option: '',
        planTypes: [
          {value: '210', label: '210 寿险'},
          {value: '211', label: '211 年金'},
          {value: '212', label: '212 投连险'},
          {value: '213', label: '213 万能寿险'},
          {value: '220', label: '220 意外险'},
          {value: '230', label: '230 健康险'},
          {value: '290', label: '290 其他'},
        ],
        updateInds: [
          {value: 'I', label: 'I--新增'},
          {value: 'U', label: 'U--更新'},
          {value: 'D', label: 'D--删除'},
        ],
        productFundtypes: [
          {value: 'Ind. Linked', label: 'Ind. Linked'},
          {value: 'Ind. PAR', label: 'Ind. PAR'},
          {value: 'Ind. Non-PAR', label: 'Ind. Non-PAR'},
          {value: 'Ind. Protection', label: 'Ind. Protection'},
          {value: 'Group', label: 'Group'},
          {value: 'Shareholder', label: 'Shareholder'},
        ],
        productTypes: [],
        productFormats: [
          {value: 'Basic plan', label: 'Basic plan'},
          {value: 'Term life', label: 'Term life'},
          {value: 'A&H rider', label: 'A&H rider'},
          {value: 'Term life rider', label: 'Term life rider'},
          {value: 'Other rider', label: 'Other rider'},
          {value: 'Standalone A&H', label: 'Standalone A&H'},
          {value: 'Group life', label: 'Group life'},
          {value: 'Group A&H', label: 'Group A&H'},
        ],
        planPeriods: [
          {value: '1', label: '1 短期（含一年期）'},
          {value: '2', label: '2 一年以上定期'},
          {value: '9', label: '9 终身'},
        ],
        yesOrno: [
          {value: 'Y', label: 'Y'},
          {value: 'N', label: 'N'},
        ],
        productBenefittriggers: [
          {value: 'Accident', label: 'Accident'},
          {value: 'Injury & Disability', label: 'Injury & Disability'},
          {value: 'Critical Ilness & CC', label: 'Critical Ilness & CC'},
          {value: 'Death', label: 'Death'},
          {value: 'Dismemberment', label: 'Dismemberment'},
          {value: 'Medical', label: 'Medical'},
          {value: 'TPD', label: 'TPD'},
          {value: 'Waiver', label: 'Waiver'},
          {value: 'Others', label: 'Others'},
        ],
        productSections: [
          {value: 'L', label: 'L=Life Asia'},
          {value: 'A', label: 'A=A & H'},
        ],

        //需要给分页组件传的信息
        paginations: {
          total: 0,        // 总数
          pageIndex: 1,  // 当前位于哪页
          pageSize: 10,   // 1页显示多少条
          pageSizes: [5, 10, 15, 20],  //每页显示多少条
          layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
        },
        pickerOptions1: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          }
        }
      }
    },
    created() {
//          this.getList();
    },
    mounted() {
      // this.getList();
    },
    methods: {
      modifyClick(row) {
        if (this.$refs['form']) {
          this.$refs['form'].resetFields();
        }
        this.showDialog = true;
        this.srpisno_temp = row.srpisno; // 修改时缓存需求号，保存时校验，如果没改变则无需校验
        Object.assign(this.form, row);
        this.form.method = 'modify';
      },
      addClick() {
        if (this.$refs['form']) {
          this.$refs['form'].resetFields();
        }
        this.srpisno_temp = '';
        this.showDialog = true;
        this.form.method = 'add';
      },
      changeProductTypes() {
        let productFundtype = this.form.productFundtype;
        if ("Ind. Linked" == productFundtype) {
          this.productTypes = [
            {value: 'Whole Life', label: 'Whole Life'},
            {value: 'Endowment', label: 'Endowment'},
            {value: 'Annuity', label: 'Annuity'}
          ]
        } else if ("Ind. PAR" == productFundtype) {
          this.productTypes = [
            {value: 'Whole Life', label: 'Whole Life'},
            {value: 'Term Life', label: 'Term Life'},
            {value: 'Endowment', label: 'Endowment'},
            {value: 'Annuity', label: 'Annuity'},
          ]
        } else if ("Ind. Non-PAR" == productFundtype) {
          this.productTypes = [
            {value: 'Whole Life', label: 'Whole Life'},
            {value: 'Term Life', label: 'Term Life'},
            {value: 'Endowment', label: 'Endowment'},
            {value: 'Annuity', label: 'Annuity'},
            {value: 'ISP', label: 'ISP'},
          ]
        } else if ("Ind. Protection" == productFundtype) {
          this.productTypes = [
            {value: 'Term Life', label: 'Term Life'},
            {value: 'H - Long Term Care', label: 'H - Long Term Care'},
            {value: 'H - Hosp Income', label: 'H - Hosp Income'},
            {value: 'H - Critical Illness', label: 'H - Critical Illness'},
            {value: 'H - Waiver of Prem.', label: 'H - Waiver of Prem.'},
            {value: 'H - Hosp & Surgical', label: 'H - Hosp & Surgical'},
            {value: 'H - Disability', label: 'H - Disability'},
            {value: 'H - Others', label: 'H - Others'},
            {value: 'Accident - H', label: 'Accident - H'},
            {value: 'Accident - Non-H', label: 'Accident - Non-H'},
            {value: 'Accident - Others', label: 'Accident - Others'},
          ]
        } else {
          this.productTypes = [
            {value: '~Undefined', label: '~Undefined'},
          ]

        }
      },

      // 查询列表
      getList() {
        this.$refs['searchForm'].validate((valid) => {
          if (valid) {
            this.paginations.total = 0;
            this.tableData = [];
            let para = {
              "crtable": this.searchParams.crtable,
              "srpisno": this.searchParams.srpisno,
              "planType": this.searchParams.planType,
              "pageSize": this.paginations.pageSize,
              "pageNumber": this.paginations.pageIndex,
            }

            this.$store.dispatch('loading/CHANGE_LOADING', true)

            api.queryList(para).then(res => {
              this.$store.dispatch('loading/CHANGE_LOADING', false)
              if (res.resultCode == constant.SUCCESS) {
                if (res.data && res.data.list.length) {
                  this.paginations.total = res.data.total;
                  this.tableData = res.data.list;
                } else {
                  this.$message({message: '无符合条件任务！', type: 'error'});
                }
              }

            }).catch(err => {
              this.$store.dispatch('loading/CHANGE_LOADING', false);
            })
          }
        });
      },
      saveData() {
        // 修改时，需求无变更则无需校验
        if (this.form.method == 'modify' && this.srpisno_temp && this.srpisno_temp == this.form.srpisno) {
          this.rules.srpisno = [];
        } else {
          this.rules.srpisno = [
            {required: true, message: '请输入需求号码', trigger: 'blur'},
            {validator: validateSrpisno, trigger: 'blur'},
            {validator: containChinese, trigger: 'blur'},
          ];
        }
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.$store.dispatch('loading/CHANGE_LOADING', true)
            api.editData(this.form).then(res => {
              this.$store.dispatch('loading/CHANGE_LOADING', false)
              if (res.resultCode == constant.SUCCESS) {
                this.showDialog = false;
                this.$message({message: '数据保存成功', type: 'success'});
                this.searchParams.crtable = this.form.crtable;
                this.getList();
              }
            }).catch(err => {
              this.$store.dispatch('loading/CHANGE_LOADING', false);
            })
          }
        });
      },
      deleteData(row) {
        this.$confirm('确定删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$store.dispatch('loading/CHANGE_LOADING', true)
          let para = {
            crtable: row.crtable
          }
          api.deleteData(para).then(res => {
            this.$store.dispatch('loading/CHANGE_LOADING', false)
            if (res.resultCode == constant.SUCCESS) {
              this.getList();
            }

          }).catch(err => {
            this.$store.dispatch('loading/CHANGE_LOADING', false);
          })
        }).catch(() => {

        });
      },
      // 每页多少条切换
      handleSizeChange(pageSize) {
        this.paginations.pageSize = pageSize;
        this.getList();
      },
      // 上下分页
      handleCurrentChange(page) {
        this.paginations.pageIndex = page;
        this.getList();
      },
      // 根据条件查询列表
      subGetList() {
        this.paginations.pageIndex = 1;
        this.getList();
      },
      // 清除查询条件
      resetSearch() {
        this.searchParams.crtable = ''; //product code
        this.searchParams.srpisno = ''; //需求号码
        this.searchParams.planType = ''; //险种类别
      },
      //用途：全角转换为半角
      //传入全角字符串，返回半角字符串
      toCDB(str) {
        let tmp = "";
        for (let i = 0; i < str.length; i++) {
          if (str.charCodeAt(i) > 65248 && str.charCodeAt(i) < 65375) {
            tmp += String.fromCharCode(str.charCodeAt(i) - 65248);
          } else {
            tmp += String.fromCharCode(str.charCodeAt(i));
          }
        }
        return tmp.toUpperCase();
      },
    },
    computed: {
      ...mapGetters(['tags']),
      reload() {
        return this.$store.state.loading.reload;
      }
    },
    activated() {
      if (this.reload) {
        this.$store.dispatch('loading/CHNAGE_RELOAD', false)
        Object.assign(this.$data, this.$options.data());
      }
    }
  }
</script>

<style lang="less" scoped>
  .fillcontain {
    padding-bottom: 0;
  }

  .contain {
    background: #fff;
    padding: 10px;
    margin-bottom: 20px;
  }

  .pagination {
    padding: 10px 20px;
    text-align: right;
  }

  .operationIcon {
    // padding: 12px;
    border: 1px solid #e5e5e5;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: inline-block;
    cursor: pointer;
    box-shadow: 0 0 3px #f9f9f9;
  }

  .search_container {
    padding: 20px 20px 0 20px;
    //    border-top: 1px solid #e1e1e1;
  }

  .common-box {
    padding-bottom: 15px;
  }

  .common-lab {
    line-height: normal !important;
    text-align: right;

    .labelName {
      text-align: right;
    }
  }
</style>



